package main

import (
	"time"
	"fmt"
)

func main041() {
	//nowTime := time.Now()

	////年月日
	//year := nowTime.Year()
	//fmt.Println(year)//2018
	//month := nowTime.Month()
	//fmt.Println(month)//10
	//y, m, d := nowTime.Date()
	//fmt.Println(y, m, d)//2018 10 20

	////周月年中的第几天
	//day := nowTime.Day()
	//yearDay := nowTime.YearDay()
	//weekday := nowTime.Weekday()
	//fmt.Println(day, yearDay, weekday)//20 293 Saturday

	////时分秒
	//fmt.Println(nowTime.Hour())//15
	//fmt.Println(nowTime.Minute())//2
	//fmt.Println(nowTime.Second())//
	//fmt.Println(nowTime.Nanosecond())//

	//创建时间
	date := time.Date(1945, time.September, 8, 15, 0, 0, 0, time.Now().Location())
	fmt.Println(date)

}

func main042() {
	//Add方法和Sub方法是相反的
	//获取t0和t1的时间距离d是使用Sub
	//将t0加d获取t1就是使用Add方法
	now := time.Now()

	//一天之前
	duration, _ := time.ParseDuration("-24h0m0s")
	fmt.Println(now.Add(duration))//

	//一周之前
	fmt.Println(now.Add(duration * 7))

	//一月之前
	fmt.Println(now.Add(duration * 30))

	//计算时间差
	fmt.Println("时间差=", now.Sub(	time.Date(1969,time.December,31,0,0,0,0,time.Now().Location())	))
}
